package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.PrivateMassage;
import cn.wolfcode.trip.base.mapper.PrivateMassageMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IPrivateMassageService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PrivateMassageServiceImpl implements IPrivateMassageService {
    @Autowired
    private PrivateMassageMapper privateMassageMapper;

    /**
     * 查询系统消息
     * @param qo
     * @return
     */
    @Override
    public PageInfo<?> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<PrivateMassage> list = privateMassageMapper.selectForList(qo);
        return new PageInfo<PrivateMassage>(list);
    }

    @Override
    public void changeState(Long id,boolean state) {
        privateMassageMapper.changeState(id,state);
    }

    @Override
    public void save(PrivateMassage pm) {
        pm.setCreatedate(new Date());
        pm.setState(true);
        privateMassageMapper.insertPrivateMessage(pm);
    }

    @Override
    public int queryMessageCount(Long id,int state) {
        return privateMassageMapper.queryMessageCount(id,state);
    }
}
